﻿namespace FamilyTree_v1._0
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    public partial class DisplayGenealogy : UserControl
    {
        public DisplayGenealogy()
        {
            InitializeComponent();
        }

        private void DisplayGenealogy_Load(object sender, EventArgs e)
        {
            LoadDataToTree();
        }
        public void LoadDataToTree()
        {
       /*     DataFamilyTreeDataContext familyDataContext = new DataFamilyTreeDataContext();
            var ancestor = (from p in familyDataContext.Persons
                            where p.LifeTime == 0
                            select p).First();
            frmMain.tree.Root=new Note(new Member(ancestor.PersonID,ancestor.FullName,ancestor.OtherName,Convert.ToBoolean(ancestor.Sex),Convert.ToDateTime(ancestor.DateOfBirth),ancestor.PlaceOfBirth,Convert.ToDateTime(ancestor.DateOfDeath),ancestor.PlaceOfDeath,Convert.ToInt32(ancestor.IDofFather),Convert.ToInt32(ancestor.IDofMother),ancestor.Notes));
            var arrPerson = from p in familyDataContext.Persons
                            select p;
            List<Person> listPerson = arrPerson.ToList();
            var arrAssociate = from a in familyDataContext.Associates
                               select a;
            List<Associate> listAssociate = arrAssociate.ToList();
            foreach (Person person in listPerson)
            {

                Note note = new Note(new Member(person.PersonID, person.FullName, person.OtherName, Convert.ToBoolean(person.Sex), Convert.ToDateTime(person.DateOfBirth), person.PlaceOfBirth, Convert.ToDateTime(person.DateOfDeath), person.PlaceOfDeath, Convert.ToInt32(person.IDofFather), Convert.ToInt32(person.IDofMother), person.Notes));
                foreach (Associate associate in listAssociate)
                {
                    if (person.PersonID == associate.PersonID)
                    {
                        var leftPerson = (from p in familyDataContext.Persons
                                          where p.PersonID == associate.LeftID
                                          select p).First();

                        Note leftNode = new Note(new Member(leftPerson.PersonID, leftPerson.FullName, leftPerson.OtherName, Convert.ToBoolean(leftPerson.Sex), Convert.ToDateTime(leftPerson.DateOfBirth), leftPerson.PlaceOfBirth, Convert.ToDateTime(leftPerson.DateOfDeath), leftPerson.PlaceOfDeath, Convert.ToInt32(leftPerson.IDofFather), Convert.ToInt32(leftPerson.IDofMother), leftPerson.Notes));
                        leftNode.ParentNode = note;
                        note.LeftNode = leftNode;
                        var rightPerson = (from p in familyDataContext.Persons
                                           where p.PersonID == associate.RightID
                                           select p).First();

                        Note rightNode = new Note(new Member(rightPerson.PersonID, rightPerson.FullName, rightPerson.OtherName, Convert.ToBoolean(rightPerson.Sex), Convert.ToDateTime(rightPerson.DateOfBirth), rightPerson.PlaceOfBirth, Convert.ToDateTime(rightPerson.DateOfDeath), rightPerson.PlaceOfDeath, Convert.ToInt32(rightPerson.IDofFather), Convert.ToInt32(rightPerson.IDofMother), rightPerson.Notes));
                        rightNode.ParentNode = note;
                        note.RightNode = rightNode;
                    }
                }
            }*/
        }
    }
}